<?php
include_once("sql.php");
$maxsize=20000;
$tim=time();
$GLOBALS['tim']=$tim;
function retaq(){
$query=" select q from aq;";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
$aq=$row[0];
return $aq;
}

function updateall()
{$tim=$GLOBALS['tim'];
if ( (isset($GLOBALS['db'])) || ($GLOBALS['db']==1)){$GLOBALS['db']=2;}
else { die(" ur answer was rite but it seems some body beat u to it");} 
$query="select * from login;";
$result=mysql_query($query);
while($row=mysql_fetch_array($result))
{if ( $row['last']!=-1){ $up= $tim - $row[4]; 
						$score= $row[3];
						$score +=$up; 
						//echo " last = $row[4] current time: $tim \n update is : $up  score will be : $score \n current score = $row[3]";			
						
						$upq= "update login set last=-1 , time=$score where id=$row[0]";
						//echo " \n $upq";
						if (!mysql_query($upq)){ echo " NOTICE : update faliure ";}
					  }
if ( $row['uname']==$_SESSION['uname']) { $ups="update login set last=$tim where uname=\"$row[1]\";";
										if (!mysql_query($ups)){ echo " NOTICE :update faliure ";}
										}
}	
$aq=retaq();
$aq++;
$uaq="update aq set q = $aq ;";
if (!mysql_query($uaq)){ echo " NOTICE :update faliure at aq";}		
$GLOBALS['db']=1;		
echo "<script type=\"text/javascript\">alert(\" u caputured the flag at $tim \n ur score is now $score\");</script>";	 
return 0;
}

function getq(){
$aq=retaq();
$query="select * from ques where qno=$aq;";
$result=mysql_query($query);
$row=mysql_fetch_array($result);
return $row;
}
?>